package com.chushouya.manager.async;


import com.chushouya.common.dto.OperateLogDTO;
import com.general.framework.web.utils.SpringUtils;
import com.chushouya.manager.service.admin.OperateLogService;
import com.general.framework.core.lang.Jsons;
import lombok.extern.slf4j.Slf4j;

import java.util.TimerTask;

/**
 * 消息模块异步工厂
 * @author leejean team
 */
@Slf4j
public class AsyncFactory {

    /**
     * 操作日志记录
     */
    public static TimerTask saveOperateLog(final OperateLogDTO operateLog) {
        return new TimerTask() {
            @Override
            public void run() {
                log.debug("===>operateLog:{}", Jsons.toJsonString(operateLog));
                try {
                    SpringUtils.getBean(OperateLogService.class).saveOperateLog(operateLog);
                } catch (Exception e) {
                    log.error("保存操作日志失败:{}, operateLog:{}", e.getMessage(), Jsons.toJsonString(operateLog));
                }
            }
        };
    }
}
